# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=poco
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.9.4
pkgrel=1
pkgdesc="POrtable COmponents C++ Libraries (mingw-w64)"
arch=('any')
url="https://pocoproject.org/"
license=("boost")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-pkg-config")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-expat"
         "${MINGW_PACKAGE_PREFIX}-libmariadbclient"
         "${MINGW_PACKAGE_PREFIX}-openssl"
         "${MINGW_PACKAGE_PREFIX}-pcre"
         "${MINGW_PACKAGE_PREFIX}-sqlite3"
         "${MINGW_PACKAGE_PREFIX}-zlib")
options=('staticlibs' 'strip')
source=(https://pocoproject.org/releases/${_realname}-${pkgver}/${_realname}-${pkgver}-all.tar.gz
        003-check-for-WIN64-and-enable-LLP64-schema.patch
        004-format-string-using-ostringstream.patch
        005-dont-compare-signed-unsigned.patch
        007-MinGW-doesnt-implement-wide-character-startup-module.patch
        008-Add-Mingw32-W64-configuration.patch
        009-Fix-compilation-on-WIN64-target.patch
        010-remove-warnings.patch
        011-cmake-mingw.patch
        012-find-mysql.patch
        013-POCO_WIN32_UTF8-redefinition.patch
        100-fix-mingw-config.patch)
sha256sums=('eb34f257b11240a711ee505f1d80c754a80a990aeb48d8d93407884df288fd77'
            'bcaa21c08aec0936a25fe387ecd93e354149a404a610b5a23870b047e5c1525f'
            'a1b95fea2c4464f25a9ddee6f2c559d391a22ae0cddda3537adf22f1258ec482'
            'ac05804b1c90d682333cb18dbc4aedc9e12508779e93edbd59d9b82d353b0013'
            'b51d192291b973185021431070654a3ac82e8f2b38780235aa5e71b44c5a0074'
            '61979c75b5577b9b0bf3fb96045b3c299a38c5dfc5048895ade73400831eb975'
            'cc50e8875743277ebf731475621960b4a3f003472c4bae5c16192805622a6507'
            '18ed83a120f1038644ac1e817c59b6d5a18e31bae2649299af7557726cf6c5df'
            '7840f9ad79dc778e416fd4e7d9ffd1bd87b9a1afe72d0a6ff626c27f743e1b0d'
            '23dfbc08e127cb8807e8f4407687fb8c91245e12cba1bf9281397e197730ba7a'
            '57ca988afad8dfd73705f677a706518d635aea2936d4de8f35ad9943c9a4b1b0'
            '27c2187dd829bca53d09f87731dca4e13eb632473e86cf6df5216f9108c1d506')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}-all
  patch -p1 -i ${srcdir}/003-check-for-WIN64-and-enable-LLP64-schema.patch
  patch -p1 -i ${srcdir}/004-format-string-using-ostringstream.patch
  patch -p1 -i ${srcdir}/005-dont-compare-signed-unsigned.patch
  patch -p1 -i ${srcdir}/007-MinGW-doesnt-implement-wide-character-startup-module.patch
  patch -p1 -i ${srcdir}/008-Add-Mingw32-W64-configuration.patch
  patch -p1 -i ${srcdir}/009-Fix-compilation-on-WIN64-target.patch
  patch -p1 -i ${srcdir}/010-remove-warnings.patch
  patch -p1 -i ${srcdir}/011-cmake-mingw.patch
  patch -p1 -i ${srcdir}/012-find-mysql.patch
  patch -p1 -i ${srcdir}/013-POCO_WIN32_UTF8-redefinition.patch
  patch -p1 -i ${srcdir}/100-fix-mingw-config.patch
}

build() {
  local _config=
  case "${CARCH}" in
    i686)
      _config=MinGW
    ;;

    x86_64)
      _config=MinGW32-W64
    ;;
  esac

  CXXFLAGS+=" -std=c++11"
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir -p "${srcdir}/build-${MINGW_CHOST}" && cd "${srcdir}/build-${MINGW_CHOST}"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE=Release \
    -DPOCO_UNBUNDLED=ON \
    -DENABLE_MONGODB=OFF \
    ../${_realname}-${pkgver}-all

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make destdir=${pkgdir} install
}
